<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link
	href="${pageContext.request.contextPath }/admin/assets/css/bootstrap.min.css"
	rel="stylesheet" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/css/style.css" />
<link
	href="${pageContext.request.contextPath }/admin/assets/css/codemirror.css"
	rel="stylesheet">
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/ace.min.css" />
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/admin/assets/css/font-awesome.min.css" />
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.min.js"></script>


<script type="text/javascript">
	window.jQuery
			|| document
					.write("<script src='${pageContext.request.contextPath }/admin/assets/js/jquery-2.0.3.min.js'>"
							+ "<"+"/script>");
</script>

<script type="text/javascript">
	if ("ontouchend" in document)
		document
				.write("<script src='${pageContext.request.contextPath }/admin/assets/js/jquery.mobile.custom.min.js'>"
						+ "<"+"/script>");
</script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/bootstrap.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/typeahead-bs2.min.js"></script>
<!-- page specific plugin scripts -->
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.dataTables.min.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/js/jquery.dataTables.bootstrap.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/admin/js/H-ui.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/admin/js/H-ui.admin.js"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/layer/layer.js"
	type="text/javascript"></script>
<script
	src="${pageContext.request.contextPath }/admin/assets/laydate/laydate.js"
	type="text/javascript"></script>
<style type="text/css">
th {
	text-align: center;
}

td {
	text-align: center;
}
</style>
<title>用户列表</title>
</head>

<body>
	<div class="page-content clearfix">
		<div id="Member_Ratings">
			<div class="d_Confirm_Order_style">

				<!---->
				<div class="border clearfix">
					<span class="l_f"> <a href="javascript:ovid()"
						id="member_add" class="btn btn-warning"><i class="icon-plus"></i>添加管理员</a>
					</span>
				</div>
				<!---->
				<div class="table_menu_list">
					<table class="table table-striped table-bordered table-hover"
						id="sample-table">
						<thead>
							<tr>
								<th>ID</th>
								<th>用户名</th>
								<th>电话号码</th>
								<th>注册时间</th>
								<th>个人说明</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<s:iterator value="#request.listAll">
								<tr>
									<td>${admin_id }</td>
									<td><u style="cursor: pointer" class="text-primary"
										onclick="member_show('管理员：${admin_name }','${pageContext.request.contextPath }/selectId','${admin_id }','500','350')">${admin_name }</u></td>
									<td>${admin_phone }</td>
									<td>${admin_time }</td>
									<td>${admin_remark }</td>
									<td class="td-manage"><%-- <a
										onClick="member_stop(this,${admin_id })" href="javascript:;"
										title="停用" class="btn btn-xs btn-success"><i
											class="icon-ok bigger-120"></i></a>  --%><a title="编辑"
										onclick="member_edit(${admin_id },'${admin_name }','${admin_pwd }','${admin_phone }','${admin_qq }','${admin_remark }','${admin_time }')"
										href="javascript:;" class="btn btn-xs btn-info"><i
											class="icon-edit bigger-120"></i></a> <a title="删除"
										href="javascript:;" onclick="member_del(this,${admin_id })"
										class="btn btn-xs btn-warning"><i
											class="icon-trash  bigger-120"></i></a></td>
								</tr>
							</s:iterator>
						</tbody>
					</table>
				</div>
			</div>
		</div>
	</div>
	<!--添加用户图层-->
	<div class="add_menber" id="add_menber_style" style="display: none">
		<ul class="page-content">
			<li><label class="label_name">编号：</label><span class="add_name"><input
					id="admin_id" name="编号" type="search" class="text_add"
					readonly="readonly" placeholder="系统默认给出" /></span>
				<div class="prompt r_f"></div></li>
			<li><label class="label_name">姓名：</label><span class="add_name"><input
					value="" id="admin_name" name="姓名" type="text" placeholder="*必填字段*"
					class="text_add" /></span>
				<div class="prompt r_f"></div></li>
			<li><label class="label_name">密码：</label><span class="add_name"><input
					id="admin_pwd" name="密码" type="text" placeholder="*必填字段*"
					class="text_add" /></span>
				<div class="prompt r_f"></div></li>
			<li><label class="label_name">电话：</label><span class="add_name"><input
					id="admin_phone" name="电话" type="text" placeholder="*必填字段*"
					class="text_add" /></span>
				<div class="prompt r_f"></div></li>
			<li><label class="label_name">Q Q：</label><span class="add_name"><input
					id="admin_qq" name="Q Q" type="text" placeholder="*必填字段*"
					class="text_add" /></span>
				<div class="prompt r_f"></div></li>
			<li><label class="label_name">说明：</label><span class="add_name"><input
					type="search" id="admin_remark" name="说明" class="text_add" /></span>
				<div class="prompt r_f"></div></li>
			<li><label class="label_name">时间：</label><span class="add_name"><input
					readonly="readonly" id="admin_time" name="时间" type="text"
					class="text_add" /></span>
				<div class="prompt r_f"></div></li>
		</ul>
	</div>
</body>
</html>
<script type="text/javascript">
	/*用户-添加*/
	$('#member_add').on('click',function() {
		$(".add_menber input").val("");
		var date = new Date(); 
		var mon = date.getMonth() + 1;
		var day = date.getDate();
		var nowDay = date.getFullYear() + "-" + (mon<10?"0"+mon:mon) + "-" +(day<10?"0"+day:day);
		$("#admin_time").val(nowDay) ;
		layer.open({
			type : 1,
			title : '添加管理员',
			maxmin : true,
			area : [ '700px', '' ],
			content : $('#add_menber_style'),
			btn : [ '提交', '取消' ],
			yes : function(index, layero) {
				var num = 0;
				var str = "";
				$(".add_menber input[type$='text']").each(
					function(n) {
						if ($(this).val() == "") {
							layer.alert(str += ""
									+ $(this).attr("name")
									+ "不能为空！\r\n", {
								title : '提示框',
								icon : 0,
							});
							num++;
							return false;
						}
					});
				if (num > 0) {
					return false;
				} else {
					var data = {
						'admin_id' : null,
						'admin_name' : $("#admin_name").val(),
						'admin_pwd' : $("#admin_pwd").val(),
						'admin_phone' : $("#admin_phone").val(),
						'admin_qq' : $("#admin_qq").val(),
						'admin_remark' : $("#admin_remark").val(),
						'admin_time' : $("#admin_time").val()
					};
					$.ajax({
						url:'${pageContext.request.contextPath }/saveAdmin',
						type:"POST",
						data:data,
						dataType:'json',
						success:function(msg){
							if(msg){
								layer.alert('添加成功！',{
						            title: '提示框',				
									icon:1,
									end: function () {
						                location.reload();//刷新页面
						            }
								});
								layer.close(index);	
							}
						},error:function(){
							layer.msg('添加失败！', {
								icon : 1,
								time : 1000
							});
						}
					});
				}
			}
		});
	});
     
	/*用户-删除*/
	function member_del(obj, id) {
		layer.confirm('确认要删除吗？', function(index) {
			 $.ajax({
				url:'${pageContext.request.contextPath }/deleteAdmin',
				type:"POST",
				data:'admin_id='+id,
				dataType:'json',
				success:function(msg){
					if(msg){
						$(obj).parents("tr").remove();
						window.location.reload(); //刷新当前页面
					}
				},error:function(){
					layer.msg('删除失败!', {
						title: '提示框',	
						icon : 1,
						time : 1200
					});
				}
			}); 
		});
	}
	
	/*用户-查看*/
	function member_show(title, url, id, w, h) {
		layer_show(title, url + '?admin_id=' + id, w, h);
	}
	/*用户-编辑*/
	function member_edit(id,name,pwd,phone,qq,remark,t) {
		alert(id+" "+name+" "+pwd+" "+phone+" "+qq+" "+remark+"  "+t);
		$("#admin_id").val(id),
		$("#admin_name").val(name),
		$("#admin_pwd").val(pwd),
		$("#admin_phone").val(phone),
		$("#admin_qq").val(qq),
		$("#admin_remark").val(remark),
		$("#admin_time").val(t)
		layer.open({
			type : 1,
			title : '修改用户信息',
			maxmin : true,
			shadeClose : false, //点击遮罩关闭层
			area : [ '700px', '' ],
			content : $('#add_menber_style'),
			btn : [ '提交', '取消' ],
			yes : function(index, layero) {
				var num = 0;
				var str = "";
				$(".add_menber input[type$='text']").each(
						function(n) {
							if ($(this).val() == "") {
								layer.alert(str += ""
										+ $(this).attr("name")
										+ "不能为空！\r\n", {
									title : '提示框',
									icon : 0,
								});
								num++;
								return false;
							}
						});
				if (num > 0) {
					return false;
				}else{
					var data = {
							'admin_id' : $("#admin_id").val(),
							'admin_name' : $("#admin_name").val(),
							'admin_pwd' : $("#admin_pwd").val(),
							'admin_phone' : $("#admin_phone").val(),
							'admin_qq' : $("#admin_qq").val(),
							'admin_remark' : $("#admin_remark").val(),
							'admin_time' : $("#admin_time").val()
						};
					$.ajax({
						url:'${pageContext.request.contextPath }/updateAdmin',
						type:"POST",
						data:data,
						success:function(msg){
							if(msg){
								layer.alert('修改成功！',{
						            title: '提示框',				
									icon:1,
									end: function () {
						                location.reload();//刷新页面
						            }
								});
								layer.close(index);	
							}
						},error:function(){
							layer.msg('修改失败！', {
								icon : 1,
								time : 1000
							});
						}
					})
				}
			}
		});
	}	
</script>
<script type="text/javascript">
	jQuery(function($) {
		var oTable1 = $('#sample-table').dataTable( {
		"aaSorting": [[ 0, "desc" ]],//默认第几个排序
		"bStateSave": true,//状态保存
		"aoColumnDefs": [
		  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
		  {"orderable":false,"aTargets":[4,5]}// 制定列不参与排序
		] } );
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});	
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			});
</script>